$(document).ready(function () {
    $.ajax({
        url:BASE_URL+'php/providers/sliderHome.provider.php',
        success:function (data) {
            var html = '';
            for (var i=0, l=data.length; i<l; i++) {
                html += '<li><img src="'+BASE_URL+'content/home/'+data[i].src+'" alt="'+data[i].caption+'" style="max-width: none; position: absolute" /></li>'
            }
            $('#fullslider ul').html(html);
            $('.flexslider').flexslider({
                animation: "fade",
                directionNav: false,
                start:function (e) {
                    var caption = $(e).find('.slides .flex-active-slide img').attr('alt');
                    $('.sliderCaption').html(caption)
                },
                after: function (e) {
                    var caption = $(e).find('.slides .flex-active-slide img').attr('alt');
                    $('.sliderCaption').html(caption)
                }
            });
            ajustarProyecto()
            $(window).resize()
        }
    })
})
$(window).resize(ajustarProyecto)

function ajustarAlto () {
    if ($(window).width() > 767) {
        var alto = $(window).height() - $('#header').height() - $('#footer').height();
        $('.flexslider').css({height:alto})
    } else {
        $('.flexslider').css({height:'auto'})
    }
    
}

function ajustarProyecto () {
    var ancho, alto;
    var anchoPantalla = $(window).width();
    if(anchoPantalla > 767){
        var anchoSlider = $(window).width();
        var altoSlider = $(window).height() - $('#header').height() - $('#footer').height();
        
        $('#home, #fullslider').width(anchoSlider).height(altoSlider)
        var anchoC = 1600;
        var altoC = 842
                    
        if ((anchoC / altoC) > (anchoSlider / altoSlider)) {
            ancho = Math.round((anchoC/altoC)*altoSlider);
            $('#fullslider img').width(ancho).height(altoSlider);
            $('#fullslider img').css({
                left:'-'+((ancho - anchoSlider) / 2)+'px', 
                top:0
            })
        } else {
            alto = Math.round((altoC/anchoC)*anchoSlider);  
            $('#fullslider img').width(anchoSlider).height(alto);
            $('#fullslider img').css({
                left:0, 
                top:'-'+((alto - altoSlider) / 2)+'px'
                })
        }
                    
                    
    }else{
        $('#home, #fullslider').css('height', 'auto')            
        $('#home, #fullslider').css('width', '100%')
        $('.flexslider img').css({
            width:'100%', 
            height:'auto', 
            position:'relative', 
            left:0, 
            top:0
        })
    }   
}

/*$(window).load(function() {
    $('.flexslider').flexslider({
        animation: "fade",
        directionNav: false
    });
});*/




